package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class foodController {
    @Autowired
    FoodService foodService;

    @RequestMapping("payTotal")
    public Object payTotal() {
        List<Map> maps = foodService.payTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",maps.get(0).get("sum"));
        return jsonObject;
    }

    @RequestMapping("zbTotal")
    public Object zbTotal() {
        List<Map> maps = foodService.zbTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name", map.get("name"));
            dataObject.put("value", map.get("sum"));
            objects.add(dataObject);
        }
        jsonObject.put("data",objects);
        return jsonObject;
    }

    @RequestMapping("proTotal")
    public Object proTotal() {
        return null;
    }
}

